package cc.telecomdigital.tdstock.activity.groups.more.push.util;

import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import cc.telecomdigital.tdstock.Framework.UniqueItem.TDStockLog;

/**
 * 
 * Project：Server_Push Package：cc.mango.test.dataDemo.util Class：XMLRead
 * Description： Creater：hunter CreateTime：Oct 10, 2011 3:13:18 PM Modifier
 * ：hunter Modify time：Oct 10, 2011 3:13:18 PM Modify Remarks： read data
 * 
 * @version 1.0
 * 
 */
public class XMLHelper
{
	private static String	TAG	= XMLHelper.class.getSimpleName();

	/**
	 * return a Dccument Object
	 * 
	 * @param input
	 * @return
	 */
	public static Document parseURL(InputStream input)
	{
		Document doc = null;

		try
		{
			DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
					.newInstance();
			DocumentBuilder docBuilder = docBuilderFactory
					.newDocumentBuilder();
			doc = docBuilder.parse(input);
		}
		catch (Exception e)
		{
			TDStockLog.d(TAG, TAG + e.toString());
			// e.printStackTrace();
		}
		TDStockLog.d(TAG, doc == null ? "doc is null" : doc.toString());
		return doc;
	}

	/**
	 * get xml document content
	 * 
	 * @param doc
	 * @return
	 */
	/*
	 * public static Map<String,String> getXMLContent(Document doc){
	 * Map<String,String> maps=new HashMap<String, String>(); NodeList
	 * nodes=doc.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) {
	 * if("NewsList".equals(nodes.item(i).getNodeName())){ NodeList
	 * newslist=nodes.item(i).getChildNodes(); for (int j = 0; j <
	 * newslist.getLength(); j++) {
	 * if("Status".equals(newslist.item(j).getNodeName())){ maps.put("Status",
	 * XMLHelper.getNodeValue(newslist.item(j))); }else
	 * if("News".equals(newslist.item(j).getNodeName())){ NodeList
	 * news=newslist.item(j).getChildNodes(); for (int k = 0; k <
	 * news.getLength(); k++) { if("ID".equals(news.item(k).getNodeName())){
	 * maps.put("ID", XMLHelper.getNodeValue(news.item(k))); }else
	 * if("DateTime".equals(news.item(k).getNodeName())){ maps.put("DateTime",
	 * XMLHelper.getNodeValue(news.item(k))); }else
	 * if("Vendor".equals(news.item(k).getNodeName())){ maps.put("Vendor",
	 * XMLHelper.getNodeValue(news.item(k))); }else
	 * if("Title".equals(news.item(k).getNodeName())){ maps.put("Title",
	 * XMLHelper.getNodeValue(news.item(k))); }else
	 * if("Content".equals(news.item(k).getNodeName())){ maps.put("Content",
	 * XMLHelper.getNodeValue(news.item(k))); }
	 * 
	 * } } } } } return maps; }
	 */

	/*	*//**
			* get node tostring of nodetype
			* 
			* @param node
			* @return
			*/
	/*
	 * public static String getNodeValue(Node node){ String str=""; NodeList
	 * temp=node.getChildNodes(); for (int i = 0; i < temp.getLength(); i++) {
	 * if(temp.item(i).getNodeType()==Node.TEXT_NODE){
	 * str=temp.item(i).toString().replace("#text:", "").replace("[",
	 * "").replace("]", "").trim(); } } return str; }
	 */
}
